/**
 * Ingenius-Group S.A.S
 *
 * Project: SAU
 * File: EditIndicator2EvaluateView.java
 * Date: 07/02/2011
 */

package com.ingenius.sau.client.view;

import com.extjs.gxt.ui.client.widget.form.TextArea;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.layout.FormData;
import com.ingenius.sau.client.presenter.EditIndicator2EvaluatePresenter.EditIndicator2EvaluateDisplay;
import com.ingenius.sau.client.view.widgets.ListBox;

/**
 * Class <strong>EditIndicator2EvaluateView</strong>
 * 
 * @author Jesus David
 * @version 0.1
 */
public class EditIndicator2EvaluateView extends AbstractEditView implements
		EditIndicator2EvaluateDisplay {

	// UI Widgets
	private final TextField<String> textName;
	private final TextField<String> textGrade;
	private final ListBox textWeighing;
	private final TextArea textDescription;
	private final TextArea textJustify;

	// Constructor

	public EditIndicator2EvaluateView() {
		super();
		textName = new TextField<String>();
		textGrade = new TextField<String>();
		textDescription = new TextArea();
		textJustify = new TextArea();
		textWeighing = new ListBox();

		// TODO i18n
		setHeading("Edit Indicator to evaluate");
		setSize(500, 400);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ingenius.sau.client.mvp.views.AbstractEditView#createComponents()
	 */
	@Override
	protected void createComponents() {
		// TODO i18n
		FormData formData = new FormData("-20");
		textName.setFieldLabel("Name");
		textName.setAllowBlank(false);
		textName.addPlugin(plugin);
		textName.setData("text", "Enter the indicator name");
		textName.getMessages().setBlankText("Name is required");

		textDescription.setFieldLabel("Description");
		textDescription.setHeight(75);
		textDescription.setAllowBlank(false);
		textDescription.addPlugin(plugin);
		textDescription.setData("text", "Any description is fine...");
		textDescription.getMessages().setBlankText("Description is required");

		textWeighing.setFieldLabel("Weighing");
		textWeighing.setAllowBlank(false);
		textWeighing.setEditable(false);
		textWeighing.addPlugin(plugin);
		textWeighing.setData("text", "Enter the indicator weighing");
		textWeighing.getMessages().setBlankText("Weighing is required");

		textJustify.setFieldLabel("Justify");
		textJustify.setHeight(75);
		textJustify.setAllowBlank(false);
		textJustify.addPlugin(plugin);
		textJustify.setData("text", "Enter the weighing justify");
		textJustify.getMessages().setBlankText("Justify is required");

		textGrade.setFieldLabel("Grade");
		textGrade.setValue("not aviable");
		textGrade.setReadOnly(true);

		form.add(textName, formData);
		form.add(textDescription, formData);
		form.add(textWeighing, formData);
		form.add(textJustify, formData);
		form.add(textGrade, formData);

		setWeighings();
	}

	@Override
	public String getName() {
		return textName.getValue();
	}

	@Override
	public void setName(String name) {
		textName.setValue(name);
	}

	@Override
	public String getDescription() {
		return textDescription.getValue();
	}

	@Override
	public void setDescription(String description) {
		textDescription.setValue(description);
	}

	@Override
	public float getWeighing() {
		float result = 0;
		try {
			result = Float.parseFloat(textWeighing.getSimpleValue());
		} catch (NumberFormatException e) {
			result = 0;
		}
		return result;
	}

	@Override
	public void setWeighing(float weighing) {
		textWeighing.setSimpleValue("" + weighing);
	}

	public void setWeighings() {
		for (float i = 1; i <= 10; i++) {
			textWeighing.add("" + i);
		}
	}

	@Override
	public String getJustify() {
		return textJustify.getValue();
	}

	@Override
	public void setJustify(String justify) {
		textJustify.setValue(justify);
	}

	@Override
	public void setGrade(float grade) {
		textGrade.setValue(grade + "");
	}

}
